package com.socket.controller

import com.base.service.IRPC_Socket
import com.yfree.global.YController
import com.yfree.socket.YSocketManager
import io.seata.spring.annotation.GlobalTransactional
import org.springframework.cloud.context.config.annotation.RefreshScope
import org.springframework.web.bind.annotation.RestController

@RefreshScope
@RestController
class Controller_Socket : YController(), IRPC_Socket {
    @GlobalTransactional
    override fun send(socketID: String, message: String): String {
        val socketIOClient = YSocketManager.socketClients[socketID]
        return if (socketIOClient == null)
            yResult(0, message = "socketID不存在")
        else {
            socketIOClient.sendEvent("server", message)
            yResult()
        }
    }
}
